<?php
/**
 * @author Nguyen van chi (chinguyen.phpdev@gmail.com)
 * @copyright 2014 - OtcSoft
 */
class Utility_model extends CI_Model
{
	/**
	 * @param Ten bang $table
	 * @param Du lieu $data
	 * @return id insert
	 */
	public function insert($table = '' , $data = '')
	{
		$this->db->insert($table, $data);
		if ($this->db->affected_rows()) {
			return $this->db->insert_id();
		}else {
			return false;
		}
	}
	
	
	/**
	 * @param  $tabel
	 * @return all table
	 */
	public function select($tabel)
	{
		$query = $this->db->get($tabel);
		if($query){
			return $query->result_array();
		}else {
			return false;
		}
	}
	
	
	/**
	 * @param $tabel
	 * @return boolean
	 */
	public function getDetail($tabel, $where, $id)
	{
		$this->db->where($where, $id);
		$query=$this->db->get($tabel);
        //echo $this->db->last_query();

		if($query){
			return $query->row();
		}else {
			return false;
		}
	}
	
	
	/**
	 * @param cot muon xoa $where
	 * @param id $id
	 * @param bang $table
	 * @param du lieu $data
	 * @return boolean
	 */
	public function updated($where , $id , $table, $data)
	{
		$this->db->where($where, $id);
		$this->db->update($table, $data);
		if($this->db->affected_rows()){
			return true;
		}else {
			return false;
		}
	}
	
	
	/**
	 * @param unknown $table
	 * @param unknown $where
	 * @param unknown $id
	 * @return boolean
	 */
	public function delete($table, $where , $id)
	{
		$this->db->where($where, $id);
		$this->db->delete($table);
		if($this->db->affected_rows()){
			return true;
		}else {
			return false;
		}
	}
	
	
	// get where STATUS = 0 // HIEN
	public function getwhere($table) 
	{
		$sql = "SELECT * FROM $table WHERE status = 0 ";
		$query = $this->db->query($sql);
		if($query){
			return $query->result_array();
		}else {
			return false;
		}
		
	}
	
	
	// get where Cate_type = 0 // HIEN
	public function getCatewhere($param)
	{
		$sql = "SELECT * FROM tbl_category WHERE cate_type = $param && status = 0 ";
		$query = $this->db->query($sql);
		if($query){
			return $query->result_array();
		}else {
			return false;
		}
	
	}
	
	
	public function selectStatus($tabel)
	{
		$this->db->where('status', 0);
		$query = $this->db->get($tabel);
		if($query){
			return $query->result_array();
		}else {
			return false;
		}
	}
	
	public function getSuport()
	{
		$sql = "SELECT * FROM tbl_suport WHERE status = 0 LIMIT 5 ";
		$query = $this->db->query($sql);
		if($query){
			return $query->result_array();
		}else {
			return false;
		}
	
	}
	
	public function getTintuc()
	{
		$sql = "SELECT * FROM tbl_content WHERE menu_id = 15 && status = 0 ORDER BY created DESC";
		$query = $this->db->query($sql);
		if($query){
			return $query->result_array();
		}else {
			return false;
		}
	
	}
	
	public function getspcungloai()
	{
		$sql = "SELECT * FROM tbl_products WHERE status = 0 ORDER BY RAND()DESC LIMIT 2  ";
		$query = $this->db->query($sql);
		if($query){
			return $query->result_array();
		}else {
			return false;
		}
	
	}
	
	public function selectSlider($tabel)
	{
		$this->db->where('status', 0);
		$query = $this->db->get($tabel);
		if($query){
			return $query->row();
		}else {
			return false;
		}
	}
	
	public function cfooter()
	{
		$sql = "SELECT * FROM tbl_cfooter WHERE status = 0 ORDER BY created DESC";
		$query = $this->db->query($sql);
		if($query){
			return $query->result_array();
		}else {
			return false;
		}
	
	}
	
	
	
	
	
	
	
}